function [steplist] = find_steps(dfile, arg, thresh, allstep)
% find steps in a trace - using difference functions.
% Modified 10/1/02 P. Manis with 'allstep' argument
% to return indices to step positions...
%

global CURRENT VOLTAGE

rate=dfile.rate(1)*dfile.nr_channel(1)/1000; % only works properly when sample rate is constant
steplist = [];
switch arg
case 'v'
   [recs, pts] = size(VOLTAGE);
   s = abs(diff(VOLTAGE')); % compute the transitions
case 'i'
   [recs, pts] = size(CURRENT);
   s = abs(diff(CURRENT')); % compute the transitions
otherwise
end;
if(nargin == 3)
   sm = mean(s')./recs; % and average across all records
   thr = max(sm)/3;  % use 1/3 of max average height to find any transitions
   sm = diff(sm); % use diff again to find only beginning of the transitions
   steplist=find(sm > thr).*rate + rate; % make short list - add rate again to compensate for second diff function
else
   for i = 1:recs
      steplist{i} = find(abs(diff(CURRENT(i,:))) > thresh)+1;
   end;   
  % steplist
end;
return
